package tcc.board.mediator;

import java.io.IOException;

import tcc.board.BoardConnection;
import tcc.board.peripherials.Leds;
import tcc.board.peripherials.Leds.LedState;
import tcc.board.peripherials.Switches;
import tcc.board.protocol.GetLedsProtocol;
import tcc.board.protocol.GetSwitchesProtocol;
import tcc.board.protocol.ProtocolParseException;
import tcc.board.protocol.SetLedsProtocol;

public class BoardInterface {
	private static BoardInterface mInstance;
	
	private BoardInterface() {
	}
	
	public static BoardInterface getInstance() {
		if (mInstance == null)
			mInstance = new BoardInterface();
		return mInstance;
	}
	
	public Leds getLeds() throws IOException {
		String request = GetLedsProtocol.buildRequest();
		String response = BoardConnection.getInstance().request(request);

		return GetLedsProtocol.parseResponse(response);
	}
	
	public void setLeds(LedState led1, LedState led2, LedState led3) throws IOException, ProtocolParseException {
		String request = SetLedsProtocol.buildRequest(led1, led2, led3);
		String response = BoardConnection.getInstance().request(request);
		
		SetLedsProtocol.parseResponse(response);
	}
	
	public Switches getSwitches() throws IOException {
		String request = GetSwitchesProtocol.buildRequest();
		String response = BoardConnection.getInstance().request(request);

		return GetSwitchesProtocol.parseResponse(response);
	}
	
}
